package org.ims.inv.web.action.card;

import java.io.File;

import org.ims.inv.web.action.BaseAppAction;

import cn.trymore.core.util.UtilResources;
import cn.trymore.core.util.excel.ExcelRowData;

public class CardBaseAction
extends BaseAppAction
{
	/**
	 * The file upload destination path.
	 */
	protected String uploadPath = "";
	
	/**
	 * The file upload temporary path.
	 */
	protected String tempPath = "";
	
	/**
	 * 重写
	 */
	protected final String MODE_OVERWRITE = "1";
	
	/**
	 * 新建
	 */
	protected final String MODE_NEW = "2";
	
	/**
	 * 取消
	 */
	protected final String MODE_CANCEL = "3";
	
	/**
	 * 初始化文件夹
	 */
	protected void initFolders ()
	{
		this.uploadPath = UtilResources.getWebRootPath() + "uploads";
		
		File localFile = new File(this.uploadPath);
		if (!localFile.exists())
		{
			localFile.mkdirs();
		}
		
		this.tempPath = this.uploadPath + "/temp";
		File tmpFile = new File(this.tempPath);
		if (!tmpFile.exists())
		{
			tmpFile.mkdirs();
		}
	}
	
	/**
	 * 获取单元格数据
	 * 
	 * @param rawData
	 * @param index
	 * @return
	 */
	protected String getCellDataByIndexFromRow (final ExcelRowData rawData, int index)
	{
		if (rawData != null)
		{
			if (rawData.getRowData().size() > index)
			{
				if (rawData.getRowData().get(index).trim().equals("null"))
				{
					return null;
				}
				
				return rawData.getRowData().get(index);
			}
		}
		
		return null;
	}
}
